//
//  YAYILineView.m
//  testForAreacode
//
//  Created by Veer on 16/6/4.
//  Copyright © 2016年 Veer. All rights reserved.
//

#import "XDottedLineView.h"

@implementation XDottedLineView

- (id)initWithFrame:(CGRect)frame
{
    self= [super initWithFrame:frame];
    if(self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.solidLineWith = 4;
        self.blankineWith = 4;
    }
    return self;
}


- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    
    if (self.lineDirect == LineDirectV) {
        CGContextSetLineWidth(context, rect.size.width);//线宽度
    }else{
        CGContextSetLineWidth(context, rect.size.height);//线宽度
    }
    
    
    CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
    CGFloat lengths[] = {self.solidLineWith, self.blankineWith};//先画4个点再画2个点
    
    CGContextSetLineDash(context, 0, lengths, 2);//注意2(count)的值等于lengths数组的长度
    
    if (self.isRound) {
        CGContextSetLineCap(context, kCGLineCapRound);
    }
    if (self.lineDirect == LineDirectV) {
        
        CGContextMoveToPoint(context, rect.size.width / 2.0, 0);
        CGContextAddLineToPoint(context, rect.size.width / 2.0, rect.size.height);
        
    }else{
        
        CGContextMoveToPoint(context, 0, rect.size.height / 2.0);
        CGContextAddLineToPoint(context, rect.size.width, rect.size.height / 2.0);
        
    }
    
    
    CGContextStrokePath(context);
    CGContextClosePath(context);
}

@end
